//
//  SecondViewController.m
//  UI外传_夜间模式
//
//  Created by dllo on 15/12/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "SecondViewController.h"
#import "NightLabel.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.view.backgroundColor = [UIColor redColor];
    
    self.navigationItem.title = @"第二页";
    
    UISwitch *nightS = [[UISwitch alloc] initWithFrame:CGRectMake(50, 150, 50, 30)];
    // 获取上次设置的开关状态
    nightS.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    [nightS addTarget:self action:@selector(nightAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:nightS];
    [nightS release];
    
    NightLabel *label = [[NightLabel alloc] initWithFrame:CGRectMake(50, 200, 50, 30)];
    label.text = @"啦啦啦";
    [self.view addSubview:label];
    [label release];
    
    
    
    
}

- (void)nightAction:(UISwitch *)sender
{
    // 将开关状态存到本地
    [[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"isNight"];
    
    NSString *command = nil;
    if (YES == sender.on) {
        command = @"night";
    } else {
        command = @"day";
    }
    
    [[NSNotificationCenter defaultCenter] postNotificationName:command object:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
